<?php

	
function nvli($arr, $index, $def = '') {
	
	if (isset($arr[$index])) {
		return $arr[$index];
	}
	
	return $def;
}


function trimByRef(&$a) {
	$a = trim($a);
}

function echoa($arr, $ret = false) {
	
    if ($ret ) return  '<pre>'.print_r($arr, true).'</pre>';
	else echo '<pre>'.print_r($arr, true).'</pre>';
	
}

function echoad($arr) {

	echo '<pre>'.print_r($arr, true).'</pre>';
	die;
}

function replaceByRef(&$value, $needle, $replace) {
	if ($value == $needle) {
		$value = $replace;
	}
}

function clientIsMobile() {
	$array_mobile = array(
				'iphone',
				'ipod', 
				'ipad', 
				'android', 
				'blackberry', 
				'opera mobi', 
				'windows ce',
				'windows phone os',
				'symbian'
				/* and more... */
				);

	$UA = isset($_SERVER['HTTP_USER_AGENT']) ? (string) $_SERVER['HTTP_USER_AGENT'] : '';
	$regex = "/(" . implode("|", $array_mobile) . ")/i";
	return preg_match($regex, $UA);	
}